package com.bwie.service.impl;

import cn.hutool.core.util.StrUtil;
import com.bwie.common.Type;
import com.bwie.common.constants.CouponConstants;
import com.bwie.common.domain.Coupon;
import com.bwie.common.domain.CouponUser;
import com.bwie.common.domain.request.CouponAdd;
import com.bwie.common.domain.request.CouponRequest;
import com.bwie.common.result.Result;
import com.bwie.controller.CouponConntroller;
import com.bwie.domain.CouponException;
import com.bwie.mapper.CouponMapper;
import com.bwie.service.CouponService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @className: CouponServiceImpl
 * @Description: TODO
 * @version: v1.８.0
 * @author: 张雨乐
 * @date: 2025/9/12 10:19
 */
@Service
public class CouponServiceImpl implements CouponService {
    @Autowired
    private CouponMapper couponMapper;

    /**
     * 优惠卷列表
     * @param couponRequest
     * @return
     */
    @Override
    public Result couponList(CouponRequest couponRequest) {
        PageHelper.startPage(couponRequest.getPageNum(),couponRequest.getPageSize());
        List<Coupon>couponList=couponMapper.couponList(couponRequest);
        PageInfo<Coupon> info = new PageInfo<>(couponList);
        return Result.success(info);
    }

    /**
     * 字典表
     * @param id
     * @return
     */
    @Override
    public Result typeList(String id) {
        List<Type>types=couponMapper.typeList(id);
        return Result.success(types);
    }
    /**
     * 添加优惠卷
     * @param couponAdd
     * @return
     */
    @Override
    public Result couponAdd(CouponAdd couponAdd) {
        String couponName = couponAdd.getCouponName();
        if (StrUtil.isBlank(couponName)){
            throw new CouponException(CouponConstants.ERROR,CouponConstants.ERROR_MSG);
        }
        couponMapper.couponAdd(couponAdd);
        return Result.success();
    }

    /**
     * 领取记录表
     * @param couponRequest
     * @return
     */

    @Override
    public Result couponUserList(CouponRequest couponRequest) {
        PageHelper.startPage(couponRequest.getPageNum(),couponRequest.getPageSize());
        List<CouponUser>couponList=couponMapper.couponUserList(couponRequest);
        PageInfo<CouponUser> info = new PageInfo<>(couponList);
        return Result.success(info);
    }

}
